package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.service.UserService;
import com.itheima.utils.Myutils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.SQLException;


@Service//servicec层中用这个注解  也可以用其他但是规范一些用指定的
public class UserServiceImpl  implements UserService {

    @Autowired   //容器需要有实现类才行  去创建
    private UserDao userDao;
    @Autowired
    private Myutils myutils;

    @Override
    public void updataMoney(Integer money,String outname,String inname) throws SQLException {
        Connection connection = myutils.getConnection();
        connection.setAutoCommit(false);
        try {
            userDao.jianqian(money,outname,inname);
            userDao.jiaqian(money,outname,inname);
            connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            connection.rollback();
        }finally {
            connection.close();
        }


    }

    @Override
    public void saveMoney(String name,Integer money) {
        userDao.saveMoney(name,money);
    }
}
